package com.douqu.game.core.entity.ext;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.entity.Player;
import com.douqu.game.core.entity.ext.data.major.CollectData;
import com.douqu.game.core.entity.ext.data.major.RefiningData;
import com.douqu.game.core.entity.ext.data.major.TalentData;
import com.douqu.game.core.factory.*;
import com.douqu.game.core.protobuf.SGCommonProto;
import com.douqu.game.core.util.CoreUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: wzf
 * 2018-03-14
 * 专业信息（采集，挖掘，锻造，炼制）
 */
public class MajorInfo extends ExtInfo{

    private CollectData collectData;

    private RefiningData refiningData;

    private TalentData talentData;

    public MajorInfo(Player player)
    {
        super(player);

        collectData = new CollectData(player);
        refiningData = new RefiningData(player);
        talentData = new TalentData(player);
    }

    @Override
    public void checkRedPointRemindAddGoods(SGCommonProto.E_GOODS_TYPE type, int id) {

    }

    @Override
    public List<SGCommonProto.E_RED_POINT_TYPE> checkRedPointRemindAllCondition(long currentTime)
    {
        List<SGCommonProto.E_RED_POINT_TYPE> list = null;
        if(CoreUtils.isFunctionUnLock(FunctionFactory.UNLOCK_MAJOR_COLLECT, player) && collectData.hasRedPointRemind()){
            if(list == null){
                list = new ArrayList<>();
            }
            list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_MAJOR);
        }

        if(CoreUtils.isFunctionUnLock(FunctionFactory.UNLOCK_MAJOR_REFINING, player) && refiningData.hasRedPointRemind()){
            if(list == null){
                list = new ArrayList<>();
            }
            if(!list.contains(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_MAJOR)){
                list.add(SGCommonProto.E_RED_POINT_TYPE.RED_POINT_TYPE_MAJOR);
            }
        }
        return list;
    }



    @Override
    public void checkInit()
    {
        collectData.checkInit();
        refiningData.checkInit();
        talentData.checkInit();
    }

    @Override
    public void init()
    {
        collectData.init();
        refiningData.init();
        talentData.init();
    }

    @Override
    public void reset(){
        collectData.reset();
        refiningData.reset();
        talentData.reset();
    }
    @Override
    public void checkReset()
    {
        collectData.checkReset();
        refiningData.checkReset();
        talentData.checkReset();
    }

    @Override
    public void writeTo(ByteBuffer buffer)
    {
        collectData.writeTo(buffer);

        refiningData.writeTo(buffer);

        //++++++++++++++++++++++++++++++++++++++++++新加的
        talentData.writeTo(buffer);

        buffer.writeBoolean(false);
        //++++++++++++++++++++++++++++++++++++++++++新加的
    }

    @Override
    public void loadFrom(ByteBuffer buffer)
    {
        collectData.loadFrom(buffer);

        refiningData.loadFrom(buffer);

        //++++++++++++++++++++++++++++++++++++++++++新加的
        talentData.loadFrom(buffer);

        buffer.readBoolean();
        //++++++++++++++++++++++++++++++++++++++++++新加的
    }


    public CollectData getCollectData() {
        return collectData;
    }

    public RefiningData getRefiningData() {
        return refiningData;
    }

    public TalentData getTalentData() {
        return talentData;
    }
}
